package com.darthsith.droidathome.core.rest.controller;

import java.util.ArrayList;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.darthsith.droidathome.core.model.ArduinoBoard;
import com.darthsith.droidathome.core.model.Sensor;
import com.darthsith.droidathome.core.service.ArduinoService;

@Controller
public class ArduinoController {
	
	@Autowired
	private ArduinoService arduinoService;
	
	@RequestMapping(value="/getSensor&id={id}&pin={pin}", method=RequestMethod.GET)
	public @ResponseBody Sensor getSensor(@PathVariable String id, @PathVariable int pin) {
		return arduinoService.getSensor(id, pin); 
	}
	
	@RequestMapping(value="/getBoardStatus&id={id}", method=RequestMethod.GET)
	public @ResponseBody ArduinoBoard getBoard(@PathVariable String id) {
		return arduinoService.getArduinoBoardStatus(id);
	}
	
	@RequestMapping(value="/getSystemStatus", method=RequestMethod.GET)
	public @ResponseBody ArrayList<ArduinoBoard> getSystem() {
		return arduinoService.getSystemStatus();
	}
	
	@RequestMapping(value="/setSensor", method=RequestMethod.POST)
	public @ResponseBody Boolean setSensor(@RequestBody Sensor sensor) {
		arduinoService.updateSensor(sensor);
		return true;
	}
	
}
